<template>
  <div class="container" ref="mainCon">
    <!-- <topTitle :titleText="titleText"></topTitle> -->
    <el-row class="topSection boxBorder">
      <div class="topBox">
        <div>
          <el-select
            v-model="projectId"
            filterable
            placeholder="请选择项目"
            @change="changeProject"
          >
            <el-option
              v-for="(item, index) of projectList"
              :key="index"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </div>
      </div>
    </el-row>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="申请日期" class="row-padding-bottom">
              <timeSelection
                @getStartTimeValue="getStartTimeValue"
                @getEndTimeValue="getEndTimeValue"
              ></timeSelection>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="状态" class="row-padding-bottom">
              <el-select
                clearable
                filterable
                placeholder="请选择"
                v-model="filterField.status"
              >
                <el-option
                  v-for="item in projectStatus"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="申请人" class="row-padding-bottom name">
                <el-input
                  placeholder="请输入姓名或身份证号"
                  clearable
                  v-model="filterField.name"
                  @blur="filterField.name = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
          </el-col>
          <!-- <el-form-item>
                            <el-button type="primary" icon="icon iconfont iconchazhao1" @click="searchList" class="commonBtn"></el-button>
                        </el-form-item> -->
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          @sort-change="sortChange"
          :max-height="tableHeight"
          :data="tableList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="name"
            label="申请人"
            align="center"
            :formatter="formatTd"
            width="140"
          ></el-table-column>
          <el-table-column
            prop="idcard"
            label="申请人身份证号"
            align="center"
            :formatter="formatTd"
            width="200px"
          ></el-table-column>
          <el-table-column
            prop="sexValue"
            label="性别"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <!-- <el-table-column prop="projectName" label="申请加入项目名称" align="center" :formatter=formatTd width = "220px"></el-table-column>  -->
          <el-table-column
            prop="projectName"
            label="申请加入项目名称"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="applyDate"
            label="申请时间"
            sortable="custom"
            align="center"
            :formatter="formatTd"
            min-width="120px"
          ></el-table-column>
          <el-table-column
            prop="statusDesc"
            label="状态"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="operatDate"
            label="审核时间"
            sortable="custom"
            align="center"
            :formatter="formatTd"
            min-width="120px"
          ></el-table-column>
          <el-table-column label="操作" align="left" width="180px">
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="
                  scope.row.status == 'REJECT' || scope.row.status == 'APPROVED'
                "
                @click="seeDetail(scope.row)"
              >
                查看详情
              </el-link>
              <el-link type="primary" @click="goDispose(scope.row)"
                ><!--  v-if="scope.row.status == 'AUDIT' && isShowUpdate" -->
                处理
              </el-link>
              <el-link
                type="primary"
                v-if="scope.row.status == 'UNCOMPLETED' && isShowUpdate"
                @click="improvedEmployee(scope.row)"
              >
                待完善信息
              </el-link>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getpageSize="getpageSize"
          @getpageNo="getpageNo"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'projectEmployeeApply',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '项目人员申请',
      advanced: false,
      tableList: [],
      filterField: {
        status: '',
        name: '',
        applyDateStart: '',
        applyDateEnd: '',
        projectId: '',
      },
      pageSize: 20,
      pageNo: 1,
      projectStatus: [],
      applyDate: [],
      isShow: false,
      requestUrl: 'api-e/cs/application/expend/listbypage',
      loading: true,
      projectList: [],
      projectId: '',
      isShowUpdate: '',
    }
  },
  created() {
    this.filterField.status = this.$route.query.status
      ? this.$route.query.status
      : ''
    this.getStatus()
    this.getProjectList()
    this.isShowUpdate =
      this.$store.state.buttonLimitsArr.indexOf('projectEmployeeApply:update') >
      -1
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    /**
     * @description: 获取开始日期
     * @param {*} urls
     * @param {*} datas
     */
    getStartTimeValue(val) {
      if (val) {
        this.filterField.applyDateStart = val
      } else {
        this.filterField.applyDateStart = ''
      }
    },
    /**
     * @description: 获取结束日期
     * @param {*} urls
     * @param {*} datas
     */
    getEndTimeValue(val) {
      if (val) {
        this.filterField.applyDateEnd = val
      } else {
        this.filterField.applyDateEnd = ''
      }
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    // 获取状态
    getStatus() {
      this.axios({
        method: 'post',
        url: 'api-e/cs/application/expend/status',
      })
        .then(
          (resp) => {
            if (!resp.data.hasError) {
              this.projectStatus = resp.data.result
            } else {
              this.$message({
                type: 'error',
                message: '获取数据失败',
              })
            }
          },
          (resp) => {
            this.$message({
              type: 'error',
              message: '获取数据失败',
            })
          }
        )
        .catch((error) => {
          this.$message.error('数据获取失败')
        })
    },
    goDispose(row) {
      this.$router.push({
        path: '/home/employee/projectApplyDetail',
        name: 'projectApplyDetail',
        query: {
          id: row.id,
          employeeId: row.employeeId,
          projectId: row.projectId,
          projectName: row.projectName,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/employee/projectEmployeeApply',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //待完善人员信息
    improvedEmployee(row) {
      this.$router.push({
        path: '/home/employee/improvedEmployeeAddJz',
        name: 'improvedEmployeeAddJz',
        query: {
          projectId: row.projectId,
          employeeId: row.employeeId,
          projectName: row.projectName,
          detail: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/employee/projectEmployeeApply',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    seeDetail(row) {
      this.$router.push({
        path: '/home/employee/projectSeeDetail',
        name: 'projectSeeDetail',
        query: {
          projectId: row.projectId,
          employeeId: row.employeeId,
          status: row.status,
          id: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/employee/projectEmployeeApply',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getProjectList() {
      this.axios({
        method: 'post',
        url: 'api-p/projectcompany/expand/current/projects',
      }).then(
        (response) => {
          if (!response.data.hasError) {
            this.projectList = response.data.result
            if (this.$route.query.projectId) {
              this.projectId = this.$route.query.projectId
              this.projectList.map((item, index) => {
                if (item.code === this.projectId) {
                  this.projectName = item.name
                }
              })
            } else {
              if (response.data.result.length > 0) {
                this.projectId = response.data.result[0].code
                this.filterField.projectId = this.projectId
              } else {
                this.projectId = '暂无关联项目'
                this.filterField.projectId = ''
              }
            }
            this.$refs.pagination.getTableListData()
          } else {
            this.projectId = '暂无关联项目'
            this.filterField.projectId = ''
            // this.projectId = "1";
          }
        },
        (response) => {
          this.projectId = '暂无关联项目'
        }
      )
      // .catch(error => {
      //   this.projectId = "暂无关联项目";
      // });
    },
    changeProject(val) {
      this.filterField.projectId = val
      this.$refs.pagination.getTableListData()
    },
  },
}
</script>

<style scoped lang="less">
.saveBtn /deep/ .iconfont {
  padding: 0 5px;
  font-size: 14px;
}
@media screen and (min-width: 1280px) and (max-width: 1366px) {
  .searchInputWidth /deep/.el-form-item__label {
    width: 70px;
  }
}

.topSection {
  background: #fff;
  border-radius: 4px 4px 0 0;
  padding: 16px 24px 16px 10px;
  .topBox {
    .projectState {
      display: inline-block;
      width: 60px;
      height: 20px;
      line-height: 20px;
      font-size: 12px;
      color: #fff;
      text-align: center;
      margin-left: 10px;
      font-weight: normal;
      margin-top: 5px;
    }
    /deep/.el-input__inner {
      width: 346px;
      font-size: 24px;
      font-weight: bold;
      color: #333333;
      border: none;
      height: 30px;
      // background: #E4EBF1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    /deep/.el-select__caret {
      color: #333;
      font-size: 20px;
      line-height: 30px;
    }
  }
  /deep/.commonTab {
    margin-top: 21px;
  }
  /deep/.is-active {
    background: #fff;
  }
}
@import '../../../static/css/filterArea.less';
</style>
